using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestWebApplication
{
	/// <summary>
	/// Summary description for AjaxTest.
	/// </summary>
	public class AjaxTest : System.Web.UI.Page
	{
		private void Page_Load(object sender, System.EventArgs e)
		{
			string operation = this.Request.QueryString["op"];

			if ( operation != null && operation.Length > 0 )
			{
				switch(operation)
				{
					case "timeout":
						this.Response.ClearContent();
						this.Response.StatusCode = 504;
						this.Response.SuppressContent = true;
						this.Response.End();
						break;

					case "abort":
						this.Response.ClearContent();
						this.Response.StatusCode = 552;
						this.Response.SuppressContent = true;
						this.Response.End();
						break;

					case "status":
						this.Response.ClearContent();

						string code = this.Request.QueryString["code"];
						if ( code != null && code.Length > 0 )
                            this.Response.StatusCode = Convert.ToInt32(code);

						this.Response.SuppressContent = true;
						this.Response.End();
						break;
                        
					case "json":
						this.Response.ClearContent();
						string[] cars = new string[] { "vw", "fiat", "ford", "renault", "chevrolet", "audi" };
						this.Response.Write("({");
						for( int i = 0 ; i < cars.Length ; i++ )
						{
							this.Response.Write("\"" + cars[i] + "\":\"" + cars[i] + "_code" + "\"");
							if ( i != cars.Length - 1 )
								this.Response.Write(",");
						}
						this.Response.Write("})");
						this.Response.ContentType = "application/json";
						this.Response.End();
						break;

					case "text":
						this.Response.ClearContent();
						this.Response.Write("Have you ever copied some text from a web page or a document and then wanted to paste it as simple text into another application without getting all the formatting from the original source? PureText makes this simple by adding a new Windows hot-key (default is WINDOWS+V) that allows you to paste text to any application without formatting.");
						this.Response.ContentType = "text/plain";
						this.Response.End();
						break;

					case "xml":
						this.Response.ClearContent();
						this.Response.Write("<root><n1></n1><n2 a=\"t\"></n2><n3/><n4><n5/></n4></root>");
						this.Response.ContentType = "text/xml";
						this.Response.End();
						break;

					case "number":
						this.Response.ClearContent();
						this.Response.Write( new Random().Next(9999).ToString() );
						this.Response.End();
						break;

					case "html":
					default:
						break;

				}
			}

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
